var nowpage = 1
//button style
function update_passwordShow(){
    document.getElementById('historyIP').style.display = "none"
    document.getElementById('update_zhifu').style.display = 'none'
    document.getElementById('update_login').style.display = "block"
    document.getElementById('update_phone').style.display = "none"

    document.getElementById('update_passwordShow').style.fontWeight = 'bold'
    document.getElementById('update_zhifuShow').style.fontWeight = 'normal'
    document.getElementById('update_telShow').style.fontWeight = 'normal'
    document.getElementById('historyIP_show').style.fontWeight = 'normal'
}
function update_zhifuShow(){
    document.getElementById('historyIP').style.display = "none"
    document.getElementById('update_zhifu').style.display = "block"
    document.getElementById('update_login').style.display = "none"
    document.getElementById('update_phone').style.display = "none"
    

    document.getElementById('update_zhifuShow').style.fontWeight = 'bold'
    document.getElementById('update_passwordShow').style.fontWeight = 'normal'
    document.getElementById('update_telShow').style.fontWeight = 'normal'
    document.getElementById('historyIP_show').style.fontWeight = 'normal'
}
function update_telShow(){
    document.getElementById('historyIP').style.display = "none"
    document.getElementById('update_zhifu').style.display = 'none'
    document.getElementById('update_login').style.display = "none"
    document.getElementById('update_phone').style.display = "block"

    document.getElementById('update_telShow').style.fontWeight = 'bold'
    document.getElementById('update_passwordShow').style.fontWeight = 'normal'
    document.getElementById('update_zhifuShow').style.fontWeight = 'normal'
    document.getElementById('historyIP_show').style.fontWeight = 'normal'
}
function historyIP_show(){
    document.getElementById('historyIP').style.display = "block"
    document.getElementById('update_zhifu').style.display = 'none'
    document.getElementById('update_login').style.display = "none"
    document.getElementById('update_phone').style.display = "none"

    document.getElementById('historyIP_show').style.fontWeight = 'bold'
    document.getElementById('update_passwordShow').style.fontWeight = 'normal'
    document.getElementById('update_zhifuShow').style.fontWeight = 'normal'
    document.getElementById('update_telShow').style.fontWeight = 'normal'
}

//历史ip
var form1_historyIP = {
    size: 10,
    page: 1,
}
var form2_historyIP = {
    total: 2000,
    pageSize: 10,
    showTotal: true,
    showTo: true,
    change: function ( i ) {
        createContent( i );
    }
}
var $content = $( ".content" );
function createContent (i) {
    form1_historyIP.page = i
    getHistoryIPdata(form1_historyIP)
}
Helper.ui.page("#page-3", form2_historyIP);
function getHistoryIPdata(form1_historyIP){
    // console.log(form1_historyIP)
    $.ajax({
        url:initObj.url + '/api/ip/selectAllIp/'+form1_historyIP.page+"/"+form1_historyIP.size,
        // data:JSON.stringify(form1),
        // data:form1,
        datatype:'json',
        type:'get',
        beforeSend: function(request) {
           request.setRequestHeader("token", form.token);
        //    console.log(form.token)
        },
        success:function(res){
            console.log(res)
            document.getElementById('historyIP_selectAll').innerHTML = ""
            for(var i=0;i<res.data.content.length;i++){
                document.getElementById('historyIP_selectAll').innerHTML += 
                "<li><span style='width:15vw;display:inline-block'>"+res.data.content[i].time+"</span><span style='width:15vw;display:inline-block'>"+res.data.content[i].ip+"</span><span style='width:15vw;display:inline-block'>"+res.data.content[i].loginAddress+"</span></li>"
            }
            
            if(form2_historyIP.total !== res.data.totalElements){
                form2_historyIP.total = res.data.totalElements
                Helper.ui.page("#page-3", form2_historyIP);
                nowpage++
            }
        }
    })
}
getHistoryIPdata(form1_historyIP)

//支付密码

function newpassword(){
    if(document.getElementById('update_zhifu_newpassword1').value !== document.getElementById('update_zhifu_newpassword2').value){
        document.getElementById('update_zhifu_error').style.opacity = '1'
        document.getElementById('update_zhifu_newpassword2').value = ""
    }
}
function send_sms_zhifu(){
    var tel = document.getElementById('update_zhifu_phone').value
    $.ajax({
        url:initObj.url + '/api/sms/sendSms/' + tel + '/修改支付密码',
        type:'get',
        datatype:'json',
        success:function(res){
            console.log(res)
        }
    })
    document.getElementById('send_sms_zhifu').style.backgroundColor = "#e3e3ec"
    var timer2 = 60
    $("#send_sms_zhifu").attr("disabled", "disabled");
    var timer1 = setInterval(() => {
        timer2--;
        document.getElementById('send_sms_zhifu').innerHTML = timer2 + "秒后重新发送"
        if(timer2 == 0){
            $("#send_sms_zhifu").removeAttr("disabled");
            document.getElementById('send_sms_zhifu').style.backgroundColor = '#666'
            document.getElementById('send_sms_zhifu').innerHTML = '发送验证码'
            clearInterval(timer1)
        }
    }, 1000);
}
function update_zhifu_OK(){
    var forget_form = {
        code:document.getElementById('update_zhifu_code').value,
        password:hex_md5(document.getElementById('update_zhifu_newpassword2').value),
        telephone:document.getElementById('update_zhifu_phone').value,
        // country:document.getElementById('update_zhifu_country').value
    }
    $.ajax({
        url:initObj.url + '/api/user/modifyPassword/' + forget_form.code + '/' + forget_form.password + '/' + forget_form.telephone,
        type:'put',
        datatype:'json',
        success:function(res){
            console.log(res)
            if(res.status == 200){
                alert('支付密码修改成功')
            }{
                alert(res.msg)
            }
        }
    })
}

//登录密码
function login_newpassword(){
    if(document.getElementById('update_login_newpassword1').value !== document.getElementById('update_login_newpassword2').value){
        document.getElementById('update_login_error').style.opacity = '1'
        document.getElementById('update_login_newpassword2').value = ""
    }
}
function send_sms_login(){
    var tel = document.getElementById('update_login_phone').value
    $.ajax({
        url:initObj.url + '/api/sms/sendSms/' + tel + '/忘记密码',
        type:'get',
        datatype:'json',
        success:function(res){
            console.log(res)
        }
    })
    document.getElementById('send_sms_login').style.backgroundColor = "#e3e3ec"
    var timer2 = 60
    $("#send_sms_login").attr("disabled", "disabled");
    var timer1 = setInterval(() => {
        timer2--;
        document.getElementById('send_sms_login').innerHTML = timer2 + "秒后重新发送"
        if(timer2 == 0){
            $("#send_sms_login").removeAttr("disabled");
            document.getElementById('send_sms_login').style.backgroundColor = '#666'
            document.getElementById('send_sms_login').innerHTML = '发送验证码'
            clearInterval(timer1)
        }
    }, 1000);
}
function update_login_OK(){
    var forget_form = {
        code:document.getElementById('update_login_code').value,
        password:hex_md5(document.getElementById('update_login_newpassword2').value),
        telephone:document.getElementById('update_login_phone').value,
    }
    $.ajax({
        url:initObj.url + '/api/user/modifyPassword/' + forget_form.code + '/' + forget_form.password + '/' + forget_form.telephone,
        type:'put',
        datatype:'json',
        success:function(res){
            console.log(res)
            if(res.status == 200){
                alert('登入密码修改成功')
            }{
                alert(res.msg)
            }
        }
    })
}

//手机号修改
function update_newphone(){
    if((update_phone_newphone1.value) !== (update_phone_newphone2.value)){
        document.getElementById('update_phone_error').style.opacity = '1'
        document.getElementById('update_phone_newphone2').value = ""
    }
}
function send_sms_newphone(){
    var tel = document.getElementById('update_phone_phone').value
    $.ajax({
        url:initObj.url + '/api/sms/sendSms/' + tel + '/修改手机号码',
        type:'get',
        datatype:'json',
        success:function(res){
            console.log(res)
        }
    })
    document.getElementById('send_sms_newphone').style.backgroundColor = "#e3e3ec"
    var timer2 = 60
    $("#send_sms_newphone").attr("disabled", "disabled");
    var timer1 = setInterval(() => {
        timer2--;
        document.getElementById('send_sms_newphone').innerHTML = timer2 + "秒后重新发送"
        if(timer2 == 0){
            $("#send_sms_newphone").removeAttr("disabled");
            document.getElementById('send_sms_newphone').style.backgroundColor = '#666'
            document.getElementById('send_sms_newphone').innerHTML = '发送验证码'
            clearInterval(timer1)
        }
    }, 1000);
}
function update_login_OK(){
    var forget_form = {
        code:document.getElementById('update_newphone_code').value,
        telephone:document.getElementById('update_phone_phone').value,
        newtelephone:document.getElementById('update_phone_newphone2').value,
        // country:document.getElementById('update_login_country').value,
        // country2:document.getElementById('update_login_country2').value
    }
    $.ajax({
        url:initObj.url + '/api/user/modifyPassword/' + forget_form.code + '/' + forget_form.telephone + '/' + forget_form.newtelephone,
        type:'put',
        datatype:'json',
        success:function(res){
            console.log(res)
            if(res.status == 200){
                alert('手机号修改成功')
            }{
                alert(res.msg)
            }
        }
    })
}